package dxn.nl.file.api;

import dxn.boot.common.entity.AuthUser;
import dxn.boot.common.entity.BaseResult;
import dxn.boot.common.entity.CsBasePageResult;
import dxn.boot.starter.web.control.BaseControl;
import dxn.boot.starter.web.security.AuthUtils;
import dxn.nl.file.service.CsUserExportColumnService;
import dxn.nl.file.biz.po.FileImportFileDetail;
import dxn.nl.file.biz.po.UserExportColumnPo;
import dxn.nl.file.biz.vo.CsUserExportTemplateVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cs/exportTemplate")
@Tag(name = "用户导出模板管理")
public class CsUserExportColumnControl extends BaseControl {

    @Resource
    private CsUserExportColumnService csUserExportColumnService;

    @Operation(summary = "保存用户导出模板")
    @RequestMapping(value = "/saveExportTemplate", method = RequestMethod.POST)
    public BaseResult<String> saveExportTemplate(@RequestBody @Valid UserExportColumnPo po) {

        AuthUser userDetails = AuthUtils.getCurrentUser();

        String result = csUserExportColumnService.saveExportTemplate(po);

        return checkAndReturnResult(result);
    }

    @Operation(summary = "删除用户导出模板")
    @RequestMapping(value = "/deleteExportTemplate", method = RequestMethod.POST)
    public BaseResult<String> deleteExportTemplate(@RequestBody @Valid CsUserExportTemplateVo po) {

        AuthUser userDetails = AuthUtils.getCurrentUser();

        String result = csUserExportColumnService.deleteExportTemplate(po);

        return checkAndReturnResult(result);
    }

    @Operation(summary = "查询用户导出模板名称")
    @RequestMapping(value = "/selectUserExportTemplateName", method = RequestMethod.POST)
    public BaseResult<List<String>> selectUserExportTemplateName(@RequestBody @Valid CsUserExportTemplateVo vo) {

        AuthUser userDetails = AuthUtils.getCurrentUser();

        List<String> result = csUserExportColumnService.selectUserExportTemplateName(vo.getOrgCode(),vo.getModeCode(),vo.getUserCode());

        return BaseResult.success(result);
    }

    @Operation(summary = "查询用户所有导出模板")
    @RequestMapping(value = "/selectAllUserExportTemplate", method = RequestMethod.POST)
    public BaseResult<List<UserExportColumnPo>> selectAllUserExportTemplate(@RequestBody @Valid CsUserExportTemplateVo vo) {

        AuthUser userDetails = AuthUtils.getCurrentUser();

        List<UserExportColumnPo> result = csUserExportColumnService.selectAllUserExportTemplate(vo.getOrgCode(),vo.getModeCode(),vo.getUserCode());

        return BaseResult.success(result);
    }

    @Operation(summary = "根据模板名称查询用户模板")
    @RequestMapping(value = "/selectExportTemplateByUser", method = RequestMethod.POST)
    public BaseResult<UserExportColumnPo> selectExportTemplateByUser(@RequestBody @Valid CsUserExportTemplateVo vo) {

        AuthUser userDetails = AuthUtils.getCurrentUser();

        UserExportColumnPo result = csUserExportColumnService.selectExportTemplateByUser(vo);

        return BaseResult.success(result);
    }

    @Operation(summary = "查询模块所有导出字段")
    @RequestMapping(value = "/selectAllModeExportColumn", method = RequestMethod.POST)
    public BaseResult<CsBasePageResult<FileImportFileDetail>> selectAllModeExportColumn(@RequestBody @Valid CsUserExportTemplateVo vo) {

        AuthUser userDetails = AuthUtils.getCurrentUser();

        HashMap<String,String> resultMap = csUserExportColumnService.selectAllModeExportColumn(vo.getModeCode());
        return BaseResult.success(resultMap);
    }
}
